package com.atsansan.mywork.login.service.impl;

import com.atsansan.mywork.login.dao.BookDao;
import com.atsansan.mywork.login.entity.BookEntity;
import com.atsansan.mywork.login.entity.UserEntity;
import com.atsansan.mywork.login.service.BookService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sansan
 * @create 2021-03-12 16:43
 */
@Service("bookService")
public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements BookService {
    @Override
    public List<BookEntity> list(){
        List<BookEntity> bookEntities = baseMapper.selectList(null);
        return bookEntities;
    }

    @Override
    public List<BookEntity> listByKey(String key) {
        QueryWrapper<BookEntity> queryWrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(key)){
            queryWrapper.and((obj)->{
                obj.eq("b_level",key).or().like("b_level",key);
            });
            return baseMapper.selectList(queryWrapper);
        }
        return null;
    }

    @Override
    public List<String> getBookLevel() {

        ArrayList<String> bLevels = baseMapper.getBookLevel();

        return bLevels;
    }

}
